package com.cdd.edumsm.service.impl;

import com.cdd.edumsm.service.MsmService;
import com.cdd.edumsm.utils.RandomUtil;
import org.apache.commons.mail.HtmlEmail;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class MsmServiceImpl implements MsmService {
    @Override
    public boolean send(String emailaddress, Map<String, Object> param) {
        try{
            HtmlEmail email = new HtmlEmail();//不用更改
            email.setHostName("smtp.qq.com");//需要修改，126邮箱为smtp.126.com,163邮箱为163.smtp.com，QQ为smtp.qq.com
            email.setCharset("UTF-8");
            email.addTo(emailaddress);// 收件地址

            email.setFrom("1978435821@qq.com", "丑嘟嘟在线学习平台");//此处填邮箱地址和用户名,用户名可以任意填写

            email.setAuthentication("1978435821@qq.com", "qqxlmilzlurqdbba");// 此处填写邮箱地址和客户端授权码

            email.setSubject("丑嘟嘟在线学习平台验证码");//此处填写邮件名，邮件名可任意填写
            email.setMsg("尊敬的用户您好,您本次注册的验证码是：" + param.get("code") + "，5分钟内有效！");//此处填写邮件内容

            email.send();
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }
}
